package com.douqu.game.core.entity.battle;

import com.bean.core.buffer.ByteBuffer;
import com.douqu.game.core.e.E_BattleResult;
import com.douqu.game.core.entity.GameObject;

/**
 * 玩家的战斗记录
 * Created by bean on 2017/7/28.
 */
public class BattleRecord extends GameObject {

    private String targetIndex;

    private int battleType;

    private int result;

    private int createTime;

    /**
     * 战斗开始时间,只精确到秒
     */
    private int startTime;

    /**
     * 战斗结束时间,只精确到秒
     */
    private int endTime;


    @Override
    public void writeTo(ByteBuffer buffer)
    {
        super.writeTo(buffer);

        buffer.writeByte(battleType);
        buffer.writeByte(result);
        buffer.writeUTF(targetIndex);
        buffer.writeInt(createTime);
        buffer.writeInt(startTime);
        buffer.writeInt(endTime);
    }

    @Override
    public void loadFrom(ByteBuffer buffer)
    {
        super.loadFrom(buffer);

        battleType = buffer.readByte();
        result = buffer.readByte();
        targetIndex = buffer.readUTF();
        createTime = buffer.readInt();
        startTime = buffer.readInt();
        endTime = buffer.readInt();
    }


    public boolean isWin()
    {
        return result == E_BattleResult.WIN.getCode();
    }

    public boolean isLose()
    {
        return result == E_BattleResult.LOSE.getCode();
    }

    public boolean isDogfall()
    {
        return result == E_BattleResult.DOGFALL.getCode();
    }



    public String getTargetIndex() {
        return targetIndex;
    }

    public void setTargetIndex(String targetIndex) {
        this.targetIndex = targetIndex;
    }

    public int getStartTime() {
        return startTime;
    }

    public void setStartTime(int startTime) {
        this.startTime = startTime;
    }

    public int getEndTime() {
        return endTime;
    }

    public void setEndTime(int endTime) {
        this.endTime = endTime;
    }

    public int getCreateTime() {
        return createTime;
    }

    public void setCreateTime(int createTime) {
        this.createTime = createTime;
    }

    public int getBattleType() {
        return battleType;
    }

    public void setBattleType(int battleType) {
        this.battleType = battleType;
    }

    public int getResult() {
        return result;
    }

    public void setResult(int result) {
        this.result = result;
    }
}
